package strategy;

import java.util.List;

import modelo.vista.CerealView;
import modelo.vista.CerealCosechaGruesaView;

public class PoliticaSiembraUltimaCoscecha implements PoliticaSiembra {

	CerealView ultimoCerealCosechado = null;
	
	public PoliticaSiembraUltimaCoscecha(CerealView ultimoCereal) {
		super();
		this.ultimoCerealCosechado = ultimoCereal;
	}


	@Override
	public List<CerealView> ceralesASembrar(List<CerealView> cereales) {
		if (ultimoCerealCosechado instanceof CerealCosechaGruesaView) {
			//use here normal for instead of foreach, otherwise would throw a ConcurrentModificationException
			//because of modification (remove) of the list during iteration
			for (int i=0; i<cereales.size(); i++) {
				CerealView c = cereales.get(i);
				if (c instanceof CerealCosechaGruesaView)
					cereales.remove(c);
			}
		}
		return cereales;
	}

}
